var jqueryGridPage = 1;
var jqueryGridRows = 10;
$(function() {
//  lotteryData();
	$('.tabHd').children().click(function() {
		var index = $(this).index();
		if (index === 0) {
			if ($("#userBets").find(".lottery").html().trim().length < 1) {
//              lotteryList('.lottery');
			}
			userBetsList('userBets', 0);
		} else if (index == 1) {
			if ($("#userBetsApp").find(".lottery").html().trim().length < 1) {
//              lotteryList('.lottery');
			}
			userBetsList('userBetsApp', 1);
		} else if (index == 2) {
			accountChange();
		} else if (index == 3) {
            commissionChange();
		} else if (index == 4) {
			lotteryReport();
		} else if (index == 5) {
            personalLotteryReport();
            if ($("#personalLotteryType").html().trim().length < 1) {
//              lotteryList('.personalLottery', 'lottery');
            }
        } else if (index == 6) {
            platformListOrder();
        } else if (index == 7) {
            egReport();
        } else if (index == 8) {
            redPacketSentList();
        } else if (index == 9) {
            redPacketReceList();
        } else if (index == 10) {
			if ($("#Wplottery").html().trim().length < 1) {
//				lotteryList('.Wplottery', 'wp');
			}
            waipanList();
        }
	});
	$(".starTime").val(laydate.now());
	$(".endTime").val(laydate.now(1));
	$("#userBets").on('click', '.butsty1', function(event) {
		if ($("#userBets").find(".lottery").html().trim().length < 1) {
            lotteryList('.lottery');
		}
		userBetsList('userBets', 0);
	});
	$("#userBetsApp").on('click', '.butsty1', function(event) {
		if ($("#userBetsApp").find(".lottery").html().trim().length < 1) {
            lotteryList('.lottery');
		}
		userBetsList('userBetsApp', 1);
	});
	$("#accountChange").on('click', '.butsty1', function(event) {
		accountChange();
	});
    // 返点账变
    $("#commissionChange").on('click', '.butsty1', function(event) {
        commissionChange();
    });
	$("#lotteryReport").on('click', '.butsty1', function(event) {
		lotteryReport();
	});
    $("#personalLotteryReport").on('click', '.butsty1', function(event) {
        personalLotteryReport();
        if ($("#personalLotteryType").html().trim().length < 1) {
            lotteryList('.personalLottery', 'lottery');
        }
    });
	$("#baccaratReport").on('click', '.butsty1', function(event) {
		baccaratReport();
	});
    $("#waipan").on('click', '.butsty1', function(event) {
        waipanList();
		if ($("#Wplottery").html().trim().length < 1) {
			lotteryList('.Wplottery', 'wp');
		}
    });
    // 报表类型切换
    $("#personalAccountType").change(function(){
        lotteryList('.personalLottery',$(this).val());
    });
	$('.tabHd').children().eq(0).trigger('click');
	
//	getHasDivend();
    getDividendLimit();
//  gethbDownUserList(true);
});

/**
 * 判断用户是否有分红权限
 */
var getDividendLimit = function() {
	$("#sourceModule option").each(function(){
		if(this.value.indexOf("dividend") >= 0) {
//			if(isShowDividend) {
//				$(this).show();
//			} else {
//				$(this).remove();
//			}
		}
	});
};

//获取订单信息（不包括追号订单）
var userBetsList = function(tabid, isChase) {
	var starTime = $("#" + tabid).find(".starTime").val();
	var endTime = $("#" + tabid).find(".endTime").val();

    if (!checkTowDate(starTime, endTime) || dateDiff(starTime, endTime) > 7) {
        popTips('查询日期不能跨月，并且时间间隔不能超过7天', 'error');
        return false;
    } else if (dateDiff(starTime, endTime) < 0) {
        popTips('查询结束日期要大于开始日期', 'error');
        return false;
    }

	var shortName = $("#" + tabid).find(".lottery").val();
	var state = $("#" + tabid).find(".state").val();
	var billNo = $("#" + tabid).find(".billNo").val();
	
	var tabs = $("#" + tabid).find("tbody");
	var htmlTitle = "<tr><th>订单号</th><th>彩种</th><th>期号</th>" +
		"<th>玩法</th><th>模式</th><th>金额</th><th>倍数</th><th>奖金</th><th>状态</th></tr>";
	tabs.empty();
	tabs.append(htmlTitle);
	$(".paging").empty();
	var pagination = $.pagination({
		render: '.paging',
		pageSize: jqueryGridRows,
		pageLength: 7,
		ajaxType: 'post',
		hideInfos: false,
		hideGo: true,
		ajaxUrl: '/ct-data/userBets/userBetsQueryList',
		ajaxData: {
			"jqueryGridPage": jqueryGridPage,
			"jqueryGridRows": jqueryGridRows,
			"starTime": starTime,
			"endTime": endTime,
			"shortName": shortName,
			"state": state,
			"billNo": billNo,
			"isChase": isChase //是否是追号 0不是追号 1追号
		},
		complete: function() {},
		success: function(data) {
			tabs.empty();
			tabs.append(htmlTitle);
			$.each(data, function(index, val) {
				var html = '<tr><td><a href="javascript:getBillInfo(\''+val.billno+'\')">' + val.billno + '</a></td>' +
					'<td>' + val.showName + '</td>' +
					'<td>' + val.expect + '</td>' +
					'<td>' + val.ruleName + '</td>' +
					'<td>' + val.priceModel + '</td>' +
					'<td>' + val.betsMoney + '</td>' +
					'<td>' + val.multiple + '</td>' +
					'<td>' + (val.prizeMoney ? val.prizeMoney : 0) + '</td>';
				if(val.state == "未中奖"){
					html += '<td class="noPrize">' + val.state + '</td>';
				}else if(val.state == "已中奖"){
					html +='<td class="prize">' + val.state + '</td>';
				}else {
					html += '<td>' + val.state + '</td>';
				}
				html += '</tr>';
				tabs.append(html);
			});
		},
		pageError: function(response) {},
		emptyData: function() {}
	});
	pagination.init();
};

//账变记录
var accountChange = function() {
	var starTime = $("#accountChange").find(".starTime").val();
	var endTime = $("#accountChange").find(".endTime").val();
	var sourceModule = $("#sourceModule").val();
	var tabs = $("#accountChange").find("tbody");
	var htmlTitle = "<tr><th>订单号</th><th>类型</th><th>金额</th><th>操作前金额</th><th>操作后金额</th><th>操作日期</th><th>备注</th></tr>";

    if (!checkTowDate(starTime, endTime) || dateDiff(starTime, endTime) > 7) {
        popTips('查询日期不能跨月，并且时间间隔不能超过7天', 'error');
        return false;
    } else if (dateDiff(starTime, endTime) < 0) {
        popTips('查询结束日期要大于开始日期', 'error');
        return false;
    }

    tabs.empty();
	tabs.append(htmlTitle);
	$(".paging").empty();
	var pagination = $.pagination({
		render: '.paging',
		pageSize: jqueryGridRows,
		pageLength: 7,
		ajaxType: 'post',
		hideInfos: false,
		hideGo: true,
		ajaxUrl: '/ct-data/accountChange/querychangeList',
		ajaxData: {
			"jqueryGridPage": jqueryGridPage,
			"jqueryGridRows": jqueryGridRows,
			"startTime": starTime,
			"endTime": endTime,
			"sourceModule": sourceModule
		},
		complete: function() {},
		success: function(data) {
			tabs.empty();
			tabs.append(htmlTitle);
			$.each(data, function(index, val) {
				/* iterate through array or object */
				var html = '<tr>';

				var sourceCode  = val.sourceCode?val.sourceCode:'';
				if( '代购'==val.sourceModuleName ||
					'撤单'==val.sourceModuleName || 
					'返奖'==val.sourceModuleName || 
					'返点'==val.sourceModuleName ||
					'后台撤单'==val.sourceModuleName) {
                    if(val.accountType == 'wp'){
                        html += '<td> <a href="javascript:getwpBillInfo(\'' + sourceCode + '\',\'changge\')">' + sourceCode + '</a></td>';
                    }else{
                        html += '<td> <a href="javascript:getBillInfo(\'' + sourceCode + '\',\'changge\')">' + sourceCode + '</a></td>';
                    }
				}else {
					html += '<td>' + sourceCode + '</td>';
				}
				html += '<td>' + val.sourceModuleName + '</td>' +
					'<td>' + val.changeAccountMoney + '</td>' +
					'<td>' + val.oldAccountMoney + '</td>' +
					'<td>' + val.newAccountMoney + '</td>' +
					'<td>' + val.operateTime + '</td>';
				var remark = val.remark;
				if(val.sourceModule == "downrecharge") {
					remark = "上级充值";
				} else if (val.remark.indexOf("绑定") >= 0) {
					remark = remark.replace((/\d{4}-\d{2}-\d{2}/), "");
				}
				html += '<td>' + remark + '</td>';
				html += '</tr>';
				tabs.append(html);
			});
		},
		pageError: function(response) {},
		emptyData: function() {}
	});
	pagination.init();
};

// 返点记录
var commissionChange = function () {
    var starTime = $("#commissionChange").find(".starTime").val();
    var endTime = $("#commissionChange").find(".endTime").val();
    if (!checkTowDate(starTime, endTime) || dateDiff(starTime, endTime) > 7) {
        popTips('查询日期不能跨月,并且时间间隔不能超过7天', 'error');
        return false;
    } else if (dateDiff(starTime, endTime) < 0) {
        popTips('查询结束日期要大于开始日期', 'error');
        return false;
    }
    var sourceModule = $("#commissionChange").find(".sourceModule").val();
    var tabs = $("#commissionChange").find("tbody");
    var htmlTitle = "<tr><th>订单号</th><th>账变类型</th><th>操作金额</th>" +
        "<th>操作前金额</th><th>操作后金额</th><th>操作日期</th><th>备注</th></tr>";
    tabs.empty();
    tabs.append(htmlTitle);
    $(".paging").empty();
    var pagination = $.pagination({
        render: '.paging',
        pageSize: jqueryGridRows,
        pageLength: 7,
        ajaxType: 'post',
        hideInfos: false,
        hideGo: true,
        ajaxUrl: '/ct-data/accountChange/querychangeCommissionList',
        ajaxData: {
            "jqueryGridPage": jqueryGridPage,
            "jqueryGridRows": jqueryGridRows,
            "startTime": starTime,
            "endTime": endTime,
            "sourceModule": sourceModule
        },
        success: function (data) {
            tabs.empty();
            tabs.append(htmlTitle);
            $.each(data, function (index, val) {
				/* iterate through array or object */
                var html = '<tr>';
                var sourceCode = val.sourceCode ? val.sourceCode : '';
                if ('代购' == val.sourceModuleName ||
                    '撤单' == val.sourceModuleName ||
                    '返奖' == val.sourceModuleName ||
                    '返点' == val.sourceModuleName ||
                    '后台撤单' == val.sourceModuleName) {
                    html += '<td> <a href="javascript:getBillInfo(\'' + sourceCode + '\')">' + sourceCode + '</a></td>';
                } else {
                    html += '<td>' + sourceCode + '</td>';
                }
                html += '<td>' + val.sourceModuleName + '</td>' +
                    '<td>' + val.changeAccountMoney + '</td>' +
                    '<td>' + val.oldAccountMoney + '</td>' +
                    '<td>' + val.newAccountMoney + '</td>' +
                    '<td>' + val.operateTime + '</td>';
                var remark = val.remark;
                if (val.sourceModule == "downrecharge") {
                    remark = "上级充值";
                } else if (val.remark.indexOf("绑定") >= 0) {
                    remark = remark.replace((/\d{4}-\d{2}-\d{2}/), "");
                }
                html += '<td>' + remark + '</td>';
                html += '</tr>';
                tabs.append(html);
            });
        },
        pageError: function (response) {
        },
        emptyData: function () {
        }
    });
    pagination.init();
};

//彩票报表
var lotteryReport = function() {
	var startTime = $("#lotteryReport").find(".starTime").val();
	var endTime = $("#lotteryReport").find(".endTime").val();
	var lotteryReportType = $("#lotteryReportType").val();
	var accountType = $("#accountType").val();
	var tabs = $("#lotteryReport").find("tbody");
	
	var header = "<tr><th>日期</th><th>充值</th><th>提款</th><th>消费</th><th>返点</th>" +
		"<th>中奖</th><th>活动</th>";
//	if(isShowDividend) {
//		header += "<th>分红</th>";
//	}
	header += "<th>盈利</th></tr>";
	tabs.empty();
	tabs.append(header);
	$(".paging").empty();
	var pagination = $.pagination({
		render: '.paging',
		pageSize: jqueryGridRows,
		pageLength: 7,
		ajaxType: 'post',
		hideInfos: false,
		hideGo: true,
		ajaxUrl: '/ct-data/lotteryReport/lotteryReportList',
		ajaxData: {
			startTime: startTime,
			endTime: endTime,
			type: lotteryReportType,
			accountType:accountType
		},
		complete: function() {},
		success: function(data) {
			tabs.empty();
			tabs.append(header);
			$.each(data, function(idx, val) {
				var dayConsumptionMoney = eval(val.latestACS.dayEnsureConsumpMoney);
				if(dayConsumptionMoney < 0) {
					dayConsumptionMoney = -dayConsumptionMoney;
				}
				var innerHtml =
					'<tr>' +
					'<td>' + val.statDate + '</td>' +
					'<td>' + val.latestACS.dayRechargeMoney + '</td>' +
					'<td>' + val.latestACS.dayDrawRechargeMoney + '</td>' +
					'<td>' + dayConsumptionMoney + '</td>' +
					'<td>' + val.latestACS.dayCommissionMoney + '</td>' +
					'<td>' + val.latestACS.dayIncomeMoney + '</td>' +
					'<td>' + val.latestACS.dayActivitiesMoney + '</td>';
				if(isShowDividend) {
					innerHtml += '<td>' + val.latestACS.dayDividendMoney + '</td>';
				}
				var profit = val.latestACS.dayEnsureConsumpMoney + val.latestACS.dayIncomeMoney + val.latestACS.dayCommissionMoney + val.latestACS.dayActivitiesMoney;
				// if(isShowDividend) {
				// 	profit += val.latestACS.dayDividendMoney;
				// }
				innerHtml += '<td>' + profit.toFixed(4) + '</td></tr>';
				tabs.append(innerHtml);
			});
		},
		pageError: function(response) {},
		emptyData: function() {}
	});
	pagination.init();
};

//个人彩票报表
var personalLotteryReport = function() {
    var startTime = $("#personalLotteryReport").find(".starTime").val();
    var endTime = $("#personalLotteryReport").find(".endTime").val();
    var lotteryReportType = $("#personalLotteryReportType").val();
    var accountType = $("#personalAccountType").val();
    var shortName = $("#personalLotteryType").val();
    var tabs = $("#personalLotteryReport").find("tbody");
    var tabsThead = $("#personalLotteryReportTh");
    var header = "</tr><th>日期</th><th>游戏类别</th><th>代购额</th><th>确认代购额</th><th>撤单金额</th>" +
        "<th>奖金</th><th>返点</th><th>盈利</th>";
    tabs.empty();
    tabsThead.empty();
    tabsThead.html(header);
    $(".paging").empty();
    var pagination = $.pagination({
        render: '.paging',
        pageSize: jqueryGridRows,
        pageLength: 7,
        ajaxType: 'post',
        hideInfos: false,
        hideGo: true,
        ajaxUrl: '/ct-data/lotteryReport/userQueryPlayRule',
        ajaxData: {
            startTime: startTime,
            endTime: endTime,
            type: lotteryReportType,
            accountType:accountType,
            shortName:shortName
        },
        complete: function() {},
        success: function(data) {
            tabs.empty();
            // tabsThead.empty();
            // if(data.length > 18){
            //     tabsThead.addClass("width-auto");
            // }else{
            //     tabsThead.removeClass("width-auto");
            // }
            $.each(data, function(idx, val) {
                var innerHtml =
                    '<tr>' +
                    '<td>' + val.statDate + '</td>' +
                    '<td>' + val.latestACS.showName + '</td>' +
                    '<td>' + Math.abs(val.latestACS.dayConsumptionMoney) + '</td>' +
                    '<td>' + Math.abs(val.latestACS.dayEnsureConsumpMoney) + '</td>' +
                    '<td>' + val.latestACS.dayCancelOrderMoney + '</td>' +
                    '<td>' + val.latestACS.dayIncomeMoney + '</td>' +
                    '<td>' + val.latestACS.dayCommissionMoney + '</td>';
                var profit = val.latestACS.dayIncomeMoney + val.latestACS.dayCommissionMoney + val.latestACS.dayEnsureConsumpMoney;
                innerHtml += '<td>' + profit.toFixed(4) + '</td></tr>';
                tabs.append(innerHtml);
            });
        },
        pageError: function(response) {},
        emptyData: function() {}
    });
    pagination.init();
};

//百家乐
var baccaratReport = function() {
	var startTime = $("#baccaratReport").find(".starTime").val();
	var endTime = $("#baccaratReport").find(".endTime").val();
	var lotteryReportType = $("#baccaratReportType").val();
	var platformCode = $("#baccaratPayment").val();
	var gameType = $("#baccaratReportGameType").val();
	var tabs = $("#baccaratReport").find("tbody");
	var header = "<tr><th>日期</th><th>转入</th><th>转出</th><th>消费</th><th>总输款</th><th>中奖</th><th>返点</th>" +
		"<th>返水</th><th>活动</th><th>盈利</th></tr>";
	tabs.empty();
	tabs.append(header);
	$(".paging").empty();
	var pagination = $.pagination({
		render: '.paging',
		pageSize: jqueryGridRows,
		pageLength: 7,
		ajaxType: 'post',
		hideInfos: false,
		hideGo: true,
		ajaxUrl: '/ct-data/baccaratReport/baccaratReportList',
		ajaxData: {
			startTime: startTime,
			endTime: endTime,
			type: lotteryReportType,
			platformCode:platformCode,
			gameType:gameType
		},
		complete: function() {},
		success: function(data) {
			tabs.empty();
			tabs.append(header);
			$.each(data, function(idx, val) {
				var dayConsumptionMoney = eval(val.latestACS.dayConsumptionMoney);
				if(dayConsumptionMoney < 0) {
					dayConsumptionMoney = -dayConsumptionMoney;
				}
				var innerHtml =
					'<tr>' +
					'<td>' + val.statDate + '</td>' +
					'<td>' + val.latestACS.dayRechargeMoney + '</td>' +
					'<td>' + val.latestACS.dayDrawRechargeMoney + '</td>' +
					'<td>' + dayConsumptionMoney + '</td>' +
					'<td>' + val.latestACS.dayLossMoney + '</td>' +
					'<td>' + val.latestACS.dayIncomeMoney + '</td>' +
					'<td>' + val.latestACS.dayCommissionMoney + '</td>' +
					'<td>' + val.latestACS.dayBackWater + '</td>' +
					'<td>' + val.latestACS.dayActivitiesMoney + '</td>' +
					'<td>' + (val.latestACS.dayBackWater +val.latestACS.dayProfitLoss + val.latestACS.dayCommissionMoney +
						val.latestACS.dayActivitiesMoney).toFixed(4) +
					'</td></tr>';
				tabs.append(innerHtml);
			});
		},
		pageError: function(response) {},
		emptyData: function() {}
	});
	pagination.init();

};

var platformListOrder = function() {
	$("#baccaratPayment").empty();
	jQuery.ajax({
		url: '/ct-data/baccarat/userPlatformList',
		type: 'POST',
		dataType: 'json',
		success: function(data, textStatus, xhr) {
			if (data.sign) {
				var html = '<option value="">全部</option>';
				$("#baccaratPayment").append(html);
				$.each(data.list, function(index, val) {
					var html = '<option value="' + val.code + '">' + val.value + '</option>';
					$("#baccaratPayment").append(html);
				});
                baccaratReport();
			} else {
				popTips(data.message, 'error');
			}
		},
		error: function(xhr, textStatus, errorThrown) {}
	});
};

//牛牛报表eg
var egReport = function() {
    var startTime = $("#egReport").find(".starTime").val();
    var endTime = $("#egReport").find(".endTime").val();
    var lotteryReportType = $("#egReportType").val();
    var tabs = $("#egReport").find("tbody");
    var header = "<tr><th class='appendDate'>转入</th><th>转出</th><th>投注金额</th><th>返水</th><th>返点</th><th>活动</th><th>抽水金额</th><th>赢单总投注额</th>" +
        "<th>和单总投注额</th><th>输单总投注额</th><th>有效总投注额</th><th>赢总额</th><th>和总额</th><th>输总额</th></tr>";
    tabs.empty();
    tabs.append(header);
    $(".paging").empty();

    var pagination = $.pagination({
        render: '.paging',
        pageSize: jqueryGridRows,
        pageLength: 7,
        ajaxType: 'post',
        hideInfos: false,
        hideGo: true,
        ajaxUrl: '/ct-data/lotteryReport/egReportList',
        ajaxData: {
            startTime: startTime,
            endTime: endTime,
            type: lotteryReportType
        },
        complete: function() {},
        success: function(data) {
            tabs.empty();
            tabs.append(header);
            if(lotteryReportType){
                tabs.find("tr:first").prepend("<th class='dates'>日期</th>");
            }
            $.each(data, function(idx, val) {

                var innerHtml ='<tr>';
                // '<td style="display: none;">' + val.reportDate + '</td>' +
                if(lotteryReportType){
                    innerHtml +='<td>' + val.reportDate + '</td>';
                }
                innerHtml +=
                    '<td>' + val.dayAmountIn + '</td>' +
                    '<td>' + val.dayAmountOut + '</td>' +
                    '<td>' + val.betAmount + '</td>' +
                    '<td>' + val.backWater + '</td>' +
                    '<td>' + val.backPoint + '</td>' +
                    '<td>' + val.activityAmount + '</td>' +
                    '<td>' + val.commissionAmount + '</td>' +
                    '<td>' + val.betWinAmount + '</td>' +
                    '<td>' + val.betDrawAmount + '</td>' +
                    '<td>' + val.betLoseAmount + '</td>' +
                    '<td>' + val.betValidAmount + '</td>' +
                    // '<td>' + val.betInvalidAmount + '</td>' +
                    '<td>' + val.winAmount + '</td>' +
                    '<td>' + val.drawAmount + '</td>' +
                    '<td>' + val.loseAmount + '</td>' +
                    '</tr>';
                console.log(tabs,innerHtml)
                tabs.append(innerHtml);
            });
        },
        pageError: function(response) {},
        emptyData: function() {}
    });
    pagination.init();
};

/********************************************* 红包 start***************************************************************/
//红包发送记录
var redPacketSentList = function() {
    var startTime = $("#redPacketSentList").find(".starTime").val();
    var endTime = $("#redPacketSentList").find(".endTime").val();
    var theme = $("#redPacketSentList").find(".theme").val();
    var type=$("#redPacketSentList").find(".redlist_type").val();
    var redPacketType=$("#redPacketSentList").find(".redlist_type option:selected").text();
    var receName= '';
    var state = $("#redPacketSentList").find(".state").val();
    if(type == 1){
        receName = $("#redPacketSentList").find(".redlist_user option:selected").text();
        if(receName == '请选择' || receName == '全部'){
            receName = '';
        }
    }else{
        receName = $("#redPacketSentList").find(".redlist_user").val();
    }
    var tabs = $("#redPacketSentList").find("tbody");
    var headertitle ="<tr class='redPacket_tr'><th></th><th></th><th></th><th style='color:red;font-weight: bolder;'>(已领取金额)</th><th style='color:red;font-weight: bolder;'>(超过24小时未被领取会退还)</th><th></th><th></th><th></th><th></th><th></th></tr>";
    var header = "<tr><th>主题</th><th>红包类型</th><th>红包金额</th><th>实际金额</th><th>退还金额</th>" +
        "<th>红包数量</th><th>已领取数量</th><th>接收人</th><th>发送时间</th><th>状态</th></tr>";
    tabs.empty();
    tabs.append(headertitle);
    tabs.append(header);
    $(".redPacket_tr th").css("line-height","16px");
    $(".paging").empty();
    var pagination = $.pagination({
        render: '.paging',
        pageSize: jqueryGridRows,
        pageLength: 7,
        ajaxType: 'post',
        hideInfos: false,
        hideGo: true,
        ajaxUrl: '/ct-data/front/redPacket/redPacketSentList',
        ajaxData: {
            startTime: startTime,
            endTime: endTime,
            theme: theme,
            type:type,
            receName: receName,
            state: state
        },
        complete: function() {},
        success: function(data) {
            tabs.empty();
            tabs.append(headertitle);
            tabs.append(header);
            $(".redPacket_tr th").css("line-height","16px");

            $.each(data, function(idx, val) {
                var innerHtml =
                    '<tr>' +
                    '<td style="max-width: 194px;cursor: pointer;" onclick="getReceMemberList(\'' + val.id + '\');">'+ val.theme + '</td>';
                // '<td>' + val.theme + '</td>' +
                // '<td>' + redPacketType + '</td>' ;
                if(val.type == 1){
                    innerHtml += '<td>个人红包</td>'
                } else if(val.type == 2){
                    innerHtml += '<td>群红包(均分)</td>'
                } else if(val.type == 3){
                    innerHtml += '<td>群红包(拼手气)</td>';
                }

                innerHtml +='<td>' + val.amount + '</td>' +
                    '<td>' + val.actualAmount + '</td>' +
                    '<td>' + val.backAmount + '</td>' +
                    '<td>' + val.count + '</td>' +
                    '<td>' + val.receiveCount + '</td>';

                if(val.receName == "all"){
                    innerHtml += '<td>平台用户</td>'
                } else if(val.receName == "down"){
                    innerHtml += '<td>下属用户</td>';
                } else{
                    innerHtml += '<td>'+val.receName+'</td>'
                }
                innerHtml +='<td>' + val.sentTime + '</td>';

                if(val.state == "未领取"){
                    innerHtml += '<td>' + val.state + '</td>'
                } else if(val.state == "已领取"){
                    innerHtml += '<td>' + val.state + '</td>'
                } else if(val.state == "已过期"){
                    innerHtml += '<td>' + val.state + '</td>'
                }else {
                    innerHtml += '<td>' + val.state + '</td>';
                }

                innerHtml +='</tr>';
                tabs.append(innerHtml);
            });
        },
        pageError: function(response) {},
        emptyData: function() {}
    });
    pagination.init();
};
//红包接收记录
var redPacketReceList = function() {
    var startTime = $("#redPacketReceList").find(".starTime").val();
    var endTime = $("#redPacketReceList").find(".endTime").val();
    var theme = $("#redPacketReceList").find(".theme").val();
    var tabs = $("#redPacketReceList").find("tbody");
    var header = "<tr><th>主题</th><th>红包金额</th><th>接收时间</th><th>发送人用户名</th><th>发送时间</th><th>状态</th></tr>";
    tabs.empty();
    tabs.append(header);
    $(".paging").empty();
    var pagination = $.pagination({
        render: '.paging',
        pageSize: jqueryGridRows,
        pageLength: 7,
        ajaxType: 'post',
        hideInfos: false,
        hideGo: true,
        ajaxUrl: '/ct-data/front/redPacket/redPacketReceList',
        ajaxData: {
            startTime: startTime,
            endTime: endTime,
            theme: theme
        },
        complete: function() {},
        success: function(data) {
            tabs.empty();
            tabs.append(header);
            $.each(data, function(idx, val) {
                var innerHtml =
                    '<tr>' +
                    '<td>' + val.theme + '</td>' +
                    '<td>' + val.amount + '</td>' +
                    '<td>' + val.receTime + '</td>'+
                    '<td>' + val.sentName + '</td>'+
                    '<td>' + val.sentTime + '</td>';

                if(val.state == "未领取"){
                    innerHtml += '<td>' + val.state + '</td>'
                } else if(val.state == "已领取"){
                    innerHtml += '<td>' + val.state + '</td>'
                } else if(val.state == "已过期"){
                    innerHtml += '<td>' + val.state + '</td>'
                }else {
                    innerHtml += '<td>' + val.state + '</td>';
                }

                innerHtml +='</tr>';
                tabs.append(innerHtml);
            });
        },
        pageError: function(response) {},
        emptyData: function() {}
    });
    pagination.init();
};
//点击红包主题查看红包接收人列表
function getReceMemberList(id) {
    var tabs = $("#getReceMemberList").find("table");
    var html = '<thead><tr><th>主题</th><th>红包金额</th><th>接收人</th><th>接收时间</th><th>状态</th></tr></thead>';
    tabs.find("thead").empty();
    tabs.prepend(html);
    $(".paging2").empty();
    var pagination = $.pagination({
        render: '.paging2',
        pageSize: jqueryGridRows,
        pageLength: 7,
        ajaxType: 'post',
        hideInfos: false,
        hideGo: true,
        ajaxUrl: '/ct-data/front/redPacket/redPacketReceMemberList',
        ajaxData: {
            redPacketId: id
        },
        complete: function() {},
        success: function(data) {
            // console.log(data,data.sign,data.sign == true)
            tabs.find("tbody").empty();
            if (data.length>0) {
                pop("getReceMemberList");
                $.each(data, function(idx, val) {
                    var innerHtml =
                        '<tr>' +
                        '<td>' + val.theme + '</td>' +
                        '<td>' + val.amount + '</td>' +
                        '<td>' + val.receName + '</td>' +
                        '<td>' + val.receTime + '</td>';

                    if(val.state == "未领取"){
                        innerHtml += '<td>' + val.state + '</td>'
                    } else if(val.state == "已领取"){
                        innerHtml += '<td>' + val.state + '</td>'
                    } else if(val.state == "已过期"){
                        innerHtml += '<td>' + val.state + '</td>'
                    }else {
                        innerHtml += '<td>' + val.state + '</td>';
                    }

                    innerHtml +='</tr>';
                    tabs.find("tbody").append(innerHtml);
                });
                var clientTbodyHeight = $("#getReceMemberList tbody").height();
                var tbodyHeight = 0;
                for(var i = 0; i< $("#getReceMemberList tbody tr").length; i++){
                    tbodyHeight += $("#getReceMemberList tbody tr").outerHeight();
                }

                if(clientTbodyHeight < tbodyHeight){
                    $("#getReceMemberList thead").css("width","calc( 98% )");
                }else{
                    $("#getReceMemberList thead").css("width","calc( 100% )");
                }
            } else {
                pop("getReceMemberList");
                tabs.find("tbody").html("<div style='text-align: center;line-height: 50px;color: red;'>暂无数据</div>");
            }
        },
        pageError: function(response) {},
        emptyData: function() {}
    });
    pagination.init();
}
/********************************************* 红包 end***************************************************************/

/***** 外盘 ***/
var waipanList = function (tabid) {
    tabid = tabid || 'waipan'
    var starTime = $("#" + tabid).find(".starTime").val();
    var endTime = $("#" + tabid).find(".endTime").val();
    console.log(starTime, endTime);
    if (!checkTowDate(starTime, endTime) || dateDiff(starTime, endTime) > 7) {
        popTips('查询日期不能跨月，并且时间间隔不能超过7天', 'error');
        return false;
    } else if (dateDiff(starTime, endTime) < 0) {
        popTips('查询结束日期要大于开始日期', 'error');
        return false;
    }

    var shortName = $("#" + tabid).find(".Wplottery").val();
    var state = $("#" + tabid).find(".state").val();
    var billNo = $("#" + tabid).find(".billNo").val();

    var tabs = $("#" + tabid).find("tbody");
    var htmlTitle = "<tr><th>订单号</th><th>彩种</th><th>期号</th>" +
        "<th>玩法</th><th>金额</th><th>奖金</th><th>状态</th></tr>";
    tabs.empty();
    tabs.append(htmlTitle);
    $(".paging").empty();
    var pagination = $.pagination({
        render: '.paging',
        pageSize: jqueryGridRows,
        pageLength: 7,
        ajaxType: 'post',
        hideInfos: false,
        hideGo: true,
        ajaxUrl: '/ct-data/wpUserBets/wpUserBetsQueryList',
        ajaxData: {
            "jqueryGridPage": jqueryGridPage,
            "jqueryGridRows": jqueryGridRows,
            "startTime": starTime,
            "endTime": endTime,
            "shortName": shortName,
            "state": state,
            "billNo": billNo
        },
        complete: function () {
        },
        success: function (data) {
            tabs.empty();
            tabs.append(htmlTitle);
            $.each(data, function (index, val) {
                var html = '<tr><td><a href="javascript:getwpBillInfo(\'' + val.billno + '\',\'waipan\')">' + val.billno + '</a></td>' +
                    '<td>' + val.showName + '</td>' +
                    '<td>' + val.expect + '</td>' +
                    '<td>' + val.ruleName + '</td>' +
                    // '<td>' + val.priceModel + '</td>' +
                    '<td>' + val.betsMoney + '</td>' +
                    // '<td>' + val.multiple + '</td>' +
                    '<td>' + (val.prizeMoney ? val.prizeMoney : 0) + '</td>';
                if (val.state == "未中奖") {
                    html += '<td class="noPrize" billno=' + val.billno + '>' + val.state + '</td>';
                } else if (val.state == "已中奖") {
                    html += '<td class="prize" billno=' + val.billno + '>' + val.state + '</td>';
                } else {
                    html += '<td billno=' + val.billno + '>' + val.state + '</td>';
                }
                html += '</tr>';
                tabs.append(html);
            });
        },
        pageError: function (response) {
        },
        emptyData: function () {
        }
    });
    pagination.init();
}